// pages/maintenance/maintenance.js
var app = getApp();
var util = require('../../utils/util.js');
var applet_park_api_url = app.globalData.applet_park_api_url;
const {
  requestDataparams
} = require('../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currenttab: '',
    showModal: false,
    items: [],
    title: '',
    type: "",
    assignorId: '',
    consignorId: '',
    todoStatusType: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.type) {
      this.data.type = options.type
    }
    if (options.assignorId) {
      this.data.assignorid = options.assignorId
    }
    if (options.consignorId) {
      this.data.consignorid = options.consignorId
    }
    if (options.todoStatusType) {
      this.data.todoStatusType = options.todoStatusType
    }
    this.setData(this.data);

  },
  packBp(e) {
    this.setData({
      currenttab: e.currentTarget.dataset.index
    })
  },
  testSubmit(e) {
    var self = this;
    var openId = wx.getStorageSync("OPENID");
    var fId = e.detail.formId; //获取formId
    
    wx.request({
      url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxcc80ff4f9e7ee858&secret=88cdd694e5804167c07f5b89b5a56d20',
      method: 'GET',
      success: function(res) {
        

        var d = {
          "keyword1": {
            "value": "00273",
            "color": "#4a4a4a"
          },
          "keyword2": {
            "value": "腾讯早餐店",
            "color": "#9b9b9b"
          },
          "keyword3": {
            "value": "66元",
            "color": "#9b9b9b"
          }

        };
        
        wx.request({
          url: 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=' + res.data.access_token,
          // header: {
          //   'content-type': 'Content-Type: application/json;',
          // },
          data: {
            touser: openId,
            template_id: "BEaKeDwRS2aPA0xfsrbSlxh7NfFeM7rSDk5wd70_WNs", //换成你申请的模板消息id，  
            page: "pages/index/index",
            form_id: e.detail.formId,
            data: d

          },
          method: 'POST',
          success: function(res) {
            
          },
          fail: function(err) {
            
          }
        })
      },
    })
  },

  formSubmit: function(e) {
    var that = this
    
    
    wx.request({
      url: "https://xxx/mobiletplus/index.php?act=login&op=send_wx",
      data: {
        "form_id": e.detail.formId,
        "customer_id": that.data.customer_id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {
        //util.showSuccess("设置成功")
        //

      },
      fail: function(e) {
        //util.showError("设置失败".e)
      }
    })
  },

  openzp: function() {
    this.setData({
      showModal: true
    })
  },

  preventTouchMove: function() {

  },


  go: function() {
    this.setData({
      showModal: false
    })
  },
  loadData() {
    let that = this;
    let id = wx.getStorageSync("id");
    


    let data = {
      type: that.data.type,
      consignorId: id
    }

    if (that.data.todoStatusType && that.data.todoStatusType != 'null' && that.data.todoStatusType != null) {
      data.consignorId = that.data.consignorid
    }
    if (that.data.type != 1) {
      data.consignorId = id
      data.todoStatusType = that.data.todoStatusType
    }


    // wx.request({
    //   url: applet_park_api_url + '/api/notifications',
    //   data: data,
    //   success(res) {
    //     
    //     
    //     if (res.data.code == 0) {
    //       // for (var row of res.data.data) {
    //       //   if (row.planningTime) {
    //       //     row.planningTime = util.ymdFormat(row.planningTime);
    //       //   }
    //       //   that.data.items.push(row);
    //       // }
    //       if (res.data.data.length == 0) {
    //         that.setData({
    //           title: '暂无更多数据',
    //         })
    //       } else {
    //         that.setData({
    //           title: '',
    //         })
    //       }
    //       that.data.items = res.data.data;
    //       that.setData(that.data);
    //     } else {
    //       wx.showToast({
    //         title: '网络异常',
    //       })
    //     }
    //   },
    //   fail(res) {
    //     wx.showToast({
    //       title: res.data,
    //     })
    //   }
    // })
    requestDataparams('/api/notifications', data, 'GET').then(res => {
      if (res.data.code == 0) {
        // for (var row of res.data.data) {
        //   if (row.planningTime) {
        //     row.planningTime = util.ymdFormat(row.planningTime);
        //   }
        //   that.data.items.push(row);
        // }
        if (res.data.data.length == 0) {
          that.setData({
            title: '暂无更多数据',
          })
        } else {
          that.setData({
            title: '',
          })
        }
        that.data.items = res.data.data;
        that.setData(that.data);
      } else {
        wx.showToast({
          title: '网络异常',
        })
      }
    }).catch(err => {
      
    });



  },
  goToDetail() {
    // pages / maintenanceDetail / maintenanceDetail
    wx.navigateTo({
      url: '../maintenanceDetail/maintenanceDetail',
    })
  },
  goexamine(e) {
    // wx.navigateTo({
    //   url: '../tenantexamine/tenantexamine',
    // })
    let type2 = e.currentTarget.dataset.type2;
    let type = e.currentTarget.dataset.type;

    let id = e.currentTarget.dataset.id;
    let todoid = e.currentTarget.dataset.todoid;
    let todoStatus = e.currentTarget.dataset.todostatus;
    let assignorid = e.currentTarget.dataset.assignorid;
    let consignorid = e.currentTarget.dataset.consignorid;
    if (type2 == 1) {
      wx.navigateTo({
        url: '../refusedetail/refusedetail?id=' + id,
      })
    } else {
      if (type == 1 && type) {
        wx.navigateTo({
          url: '../Employe_examine/Employe_examine?id=' + id + '&todoid=' + todoid + "&todoStatus=" + todoStatus + "&assignorid=" + assignorid + "&consignorid=" + consignorid,
        })
      } else {
        wx.navigateTo({
          url: '../tenantexamine/tenantexamine?id=' + id + '&todoid=' + todoid + "&todoStatus=" + todoStatus + "&assignorid=" + assignorid + "&consignorid=" + consignorid,
        })
      }
    }


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.stopPullDownRefresh();
    this.loadData();
    wx.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 2000
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})